package easy;

public class Solution_383 {

    public static boolean canConstruct(String ransomNote, String magazine) {
        int[] arr = new int[52];
        char[] chars = ransomNote.toCharArray();
        for (char c : chars) {
            if (97<=c && c<=122) {
                // a~z
                arr[c-97]++;
            } else if (65<=c && c<=90) {
                // A~Z
                arr[c-65+26]++;
            }
        }
        int length = chars.length, index;
        char[] array = magazine.toCharArray();
        for (char c : array) {
            if (length==0) {
                return true;
            }
            if (97<=c && c<=122) {
                // a~z
                index = c-97;
                if (arr[index]>0) {
                    arr[index]--;
                    length--;
                }
            } else if (65<=c && c<=90) {
                // A~Z
                index = c-65+26;
                if (arr[index]>0) {
                    arr[index]--;
                    length--;
                }
            }
        }
        return length==0;
    }

    public static void main(String[] args) {
        //2126753390
        //1702766719
//        System.out.println(guessNumber(2126753390));
        System.out.println(canConstruct("aa", "abb"));
    }
}
